package com.mctuoluo.mappay;

import org.bukkit.ChatColor;
import org.bukkit.entity.*;
import java.util.*;
import org.bukkit.scheduler.*;
import org.bukkit.plugin.*;

public class TitleTask
{
    private static Player player;
    private static List<String> titles;
    private static int ti;
    private final Player p;
    private final List<String> title;
    private int pos;
    private int ticks;
    private MapPay mapPay = MapPay.getMapPay();

    public static void send(final Player p, final List<String> title, final int ticks) {
        TitleTask.player = p;
        TitleTask.titles = title;
        TitleTask.ti = ticks;
        new TitleTask();
    }
    
    private TitleTask() {
        this.p = TitleTask.player;
        this.title = TitleTask.titles;
        this.ticks = TitleTask.ti;
        final BukkitRunnable br = new BukkitRunnable() {
            public void run() {
                if (TitleTask.this.pos == TitleTask.this.title.size()) {
                    this.cancel();
                }
                else {
                    try {
                        TitleAPI.sendTitle(TitleTask.this.p, 0, 40, 20, color(TitleTask.this.title.get(TitleTask.this.pos)), "");
                        TitleTask.access$3(TitleTask.this, TitleTask.this.pos + 1);
                    }
                    catch (Exception io) {
                        this.cancel();
                    }
                }
            }
        };
        br.runTaskTimer(mapPay, (long)this.ticks, (long)this.ticks);
    }
    
    static void access$3(final TitleTask titleTask, final int pos) {
        titleTask.pos = pos;
    }
    public static String color(final String s) {
        return ChatColor.translateAlternateColorCodes('&', s);
    }
}
